//
//  ASPracUnitGenerateCodeVC.m
//  AttendenceSys
//
//  Created by 窦芳俊 on 2017/4/1.
//  Copyright © 2017年 窦芳俊. All rights reserved.
//

#import "ASPracUnitGenerateCodeVC.h"
#import "ASLoadPracUnitCodeVC.h"

@interface ASPracUnitGenerateCodeVC () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *codeTableView;
@property (nonatomic, strong) NSArray     *codeArray;

@end


@implementation ASPracUnitGenerateCodeVC

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    _codeArray = @[@"进场", @"离场"];
    [self initView];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (void)initView
{
    UIImageView* bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0,
                                                                        0,
                                                                        self.view.frame.size.width,
                                                                        self.view.frame.size.height)];
    bgView.backgroundColor = [UIColor whiteColor];
    //bgView.image = [UIImage imageNamed:@"bg_personal"];
    bgView.userInteractionEnabled = YES;
    [self.view addSubview:bgView];
    
    _codeTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    _codeTableView.frame = CGRectMake(0, 0, self.view.frame.size.width, 100);
    _codeTableView.delegate = self;
    _codeTableView.dataSource = self;
    _codeTableView.backgroundColor = [UIColor whiteColor];
    _codeTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    [bgView addSubview:_codeTableView];
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_codeArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"generateCodeCellIdentifier"];
    
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                      reuseIdentifier:@"generateCodeCellIdentifier"];
    }
    
    cell.textLabel.text = [_codeArray objectAtIndex:[indexPath row]];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50.0f;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    ASLoadPracUnitCodeVC *vc = [[ASLoadPracUnitCodeVC alloc] initWithCodeType:([indexPath row]+1)
                                                                       unitId:[ASAppDelegate sharedAppDelegate].pracUnitUserInfo.pkAccountId];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

@end



